package com.gitee.cashzhang27.test.boot.crypt.mapper.entity;

import lombok.Data;

/**
 * @author cash Zhang
 * @since : 2018/12/09 11:04
 */
@Data
public class ObjectRestResponse<T> {

  private int status = 200;
  private String message;
  private T data;

  public static ObjectRestResponse ok() {
    return restResult(200, "success", null);
  }

  public static <T> ObjectRestResponse<T> ok(T data) {
    return restResult(200, "success", data);
  }

  public static <T> ObjectRestResponse<T> ok(Integer status, String msg, T data) {
    return restResult(status, msg, data);
  }

  public static <T> ObjectRestResponse<T> failed(Integer status, String msg) {
    return restResult(status, msg, null);
  }

  public static <T> ObjectRestResponse<T> failed(Integer status, String msg, T data) {
    return restResult(status, msg, data);
  }

  private static <T> ObjectRestResponse<T> restResult(Integer status, String msg, T data) {
    ObjectRestResponse<T> apiResult = new ObjectRestResponse<>();
    apiResult.setStatus(status);
    apiResult.setMessage(msg);
    apiResult.setData(data);
    return apiResult;
  }

}
